package nl.hanze.designpatterns.DAO.impl.file.crypted;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import nl.hanze.designpatterns.io.CryptedOutputStream;

public class LoginCredCreator {
	
	public static final String CRED_PATH = "credentials.clc";
	
	public static final void create(){
		if(!new File(LoginCredCreator.CRED_PATH).isFile()){
			try {
				byte[] bytes = ("admin").getBytes("UTF-8");
				byte[] hashKey = MessageDigest.getInstance("MD5").digest(bytes);
				FileOutputStream output = new FileOutputStream(LoginCredCreator.CRED_PATH);
				CryptedOutputStream outputStream = new CryptedOutputStream(output, hashKey);
				outputStream.write("admin::admin".getBytes("UTF-8"));
				outputStream.write("hbharms::wachtwoord".getBytes("UTF-8"));
				outputStream.write("SEGVeenstra::wachtwoord".getBytes("UTF-8"));
				outputStream.close();
				
			} catch (NoSuchAlgorithmException | IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}

}
